package com.atguigu.common.exception;


//import org.apache.poi.poifs.filesystem.DirectoryEntry;
//import org.apache.poi.poifs.filesystem.DocumentEntry;
//import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import java.io.*;


public class pdfTest2 {


//    public static void createWordForHtml(String fileName) {
//        try {
//            String html = readToString("C:\\Users\\Administrator\\Desktop\\index2.html");
//            String old = "{\"&\":\"&\",\"<\":\"<\",\">\":\">\",'\"':\"\"\",\"'\":\"&#39;\"};";
//            String new1 = "{\"&\":\"&amp;\",\"<\":\"&lt;\",\">\":\"&gt;\",'\"':\"&quot;\",\"'\":\"&#39;\"};";
//            html =  html.replace(old,new1);
//            String savePath = "文件路径"+fileName+".doc";
//            //html = html.replace("&lt;", "<").replace("&gt;", ">").replace("&quot;", "\"").replace("&amp;", "&");
//            String content="<html><body>"+html+"</body></html>";
//            System.out.println(content);
//            byte b[] = content.getBytes("GBK");  //这里是必须要设置编码的，不然导出中文就会乱码。
//
//            ByteArrayInputStream bais = new ByteArrayInputStream(b);//将字节数组包装到流中
//            /*
//             * 关键地方
//             * 生成word格式 */
//            POIFSFileSystem poifs = new POIFSFileSystem();
//            DirectoryEntry directory = poifs.getRoot();
//            DocumentEntry documentEntry = directory.createDocument("WordDocument", bais);
//            OutputStream ostream = new FileOutputStream(savePath);
//
//            poifs.writeFilesystem(ostream);  	//写入内容
//            bais.close();
//            ostream.close();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//    public static  String readToString(String fileName) {
//        String encoding = "UTF-8";
//        File file = new File(fileName);
//        Long filelength = file.length();
//        byte[] filecontent = new byte[filelength.intValue()];
//        try {
//            FileInputStream in = new FileInputStream(file);
//            in.read(filecontent);
//            in.close();
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        try {
//            return new String(filecontent, encoding);
//        } catch (UnsupportedEncodingException e) {
//            System.err.println("The OS does not support " + encoding);
//            e.printStackTrace();
//            return null;
//        }
//    }
//
//    public static void main(String[] args) {
//        //System.out.println(readToString("C:\\Users\\Administrator\\Desktop\\index.html"));
//        createWordForHtml("123");
//    }

}
